<template>
  <div class="path-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <h2>学习路径</h2>
          <el-radio-group v-model="category" size="small" @change="handleCategoryChange">
            <el-radio-button label="all">全部</el-radio-button>
            <el-radio-button label="frontend">前端开发</el-radio-button>
            <el-radio-button label="backend">后端开发</el-radio-button>
            <el-radio-button label="mobile">移动开发</el-radio-button>
            <el-radio-button label="ai">人工智能</el-radio-button>
          </el-radio-group>
        </div>
      </template>

      <div class="path-list">
        <el-card
          v-for="path in paths"
          :key="path.id"
          class="path-card"
        >
          <div class="path-cover">
            <el-image :src="path.cover" fit="cover" />
            <div class="path-tags">
              <el-tag v-if="path.isNew" type="success" size="small">新</el-tag>
              <el-tag v-if="path.isHot" type="danger" size="small">热门</el-tag>
            </div>
          </div>

          <div class="path-info">
            <h4 class="path-title">{{ path.title }}</h4>
            <p class="path-desc">{{ path.description }}</p>

            <div class="path-meta">
              <div class="stats">
                <span>
                  <el-icon><Collection /></el-icon>
                  {{ path.courseCount }}门课程
                </span>
                <span>
                  <el-icon><User /></el-icon>
                  {{ path.studentCount }}人学习
                </span>
                <span>
                  <el-icon><Star /></el-icon>
                  {{ path.rating }}分
                </span>
              </div>

              <div class="duration">
                <el-icon><Timer /></el-icon>
                预计学习时长：{{ path.duration }}
              </div>
            </div>

            <div class="path-footer">
              <div class="tags">
                <el-tag
                  v-for="tag in path.tags"
                  :key="tag"
                  size="small"
                >
                  {{ tag }}
                </el-tag>
              </div>
              <el-button type="primary" @click="handleStart(path)">
                开始学习
              </el-button>
            </div>
          </div>
        </el-card>
      </div>

      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :total="total"
          :page-sizes="[12, 24, 36, 48]"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  Collection,
  User,
  Star,
  Timer
} from '@element-plus/icons-vue'

const router = useRouter()

// 分类筛选
const category = ref('all')

// 分页
const currentPage = ref(1)
const pageSize = ref(12)
const total = ref(100)

// 学习路径数据
const paths = ref([
  {
    id: 1,
    title: 'Vue.js 全栈开发工程师',
    description: '从零开始，系统学习 Vue.js 全栈开发，包含前端、后端、数据库等完整技术栈',
    cover: 'https://example.com/path1.jpg',
    isNew: true,
    isHot: true,
    courseCount: 20,
    studentCount: 5000,
    rating: 4.8,
    duration: '3个月',
    tags: ['Vue.js', 'Node.js', 'MongoDB', '全栈开发']
  },
  {
    id: 2,
    title: 'React 高级工程师',
    description: '深入学习 React 高级特性，掌握状态管理、性能优化、测试等进阶技能',
    cover: 'https://example.com/path2.jpg',
    isNew: false,
    isHot: true,
    courseCount: 15,
    studentCount: 3000,
    rating: 4.9,
    duration: '2个月',
    tags: ['React', 'Redux', 'TypeScript', '前端开发']
  }
])

// 切换分类
const handleCategoryChange = () => {
  currentPage.value = 1
  fetchPaths()
}

// 获取学习路径列表
const fetchPaths = () => {
  // TODO: 根据分类和分页获取数据
}

// 切换页码
const handleCurrentChange = (page) => {
  currentPage.value = page
  fetchPaths()
}

// 切换每页条数
const handleSizeChange = (size) => {
  pageSize.value = size
  currentPage.value = 1
  fetchPaths()
}

// 开始学习
const handleStart = (path) => {
  router.push(`/learning/path/${path.id}`)
}
</script>

<style scoped>
.path-container {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  margin: 0;
  font-size: 20px;
}

.path-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin: 20px 0;
}

.path-card {
  cursor: pointer;
  transition: transform 0.3s;
}

.path-card:hover {
  transform: translateY(-5px);
}

.path-cover {
  position: relative;
  height: 200px;
}

.path-cover .el-image {
  width: 100%;
  height: 100%;
}

.path-tags {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}

.path-info {
  padding: 15px;
}

.path-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: bold;
}

.path-desc {
  margin: 0 0 15px;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.path-meta {
  margin-bottom: 15px;
}

.stats {
  display: flex;
  gap: 15px;
  margin-bottom: 10px;
  color: var(--el-text-color-secondary);
  font-size: 14px;
}

.stats span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.duration {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--el-text-color-secondary);
  font-size: 14px;
}

.path-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tags {
  display: flex;
  gap: 5px;
}

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style> 